﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Data
Imports System.Windows.Forms
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.BUSS
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.DTO

Namespace DoAnQuanLyBanHang.DAO
    Public Class PhanQuyenCtrl
        Private m_PhanQuyenData As New PhanQuyenData()
        Private m_PhanQuyenInfo As New PhanQuyenInfo()

        Public Sub HienThiComboBox(cbx As ComboBox)
            Dim m_DT As New DataTable()
            cbx.DataSource = m_DT
            cbx.DisplayMember = "TenDangNhap"
            cbx.ValueMember = "MaQuyen"
        End Sub

#Region "Hien thi ComboBox trong DataGridView"
        Public Sub HienThiDataGridViewComboBoxColumn(cmbColumn As DataGridViewComboBoxColumn)
            cmbColumn.DataSource = m_PhanQuyenData.LayPhanQuyen()
            cmbColumn.DisplayMember = "TenDangNhap"
            cmbColumn.ValueMember = "MaQuyen"
            cmbColumn.DataPropertyName = "MaQuyen"
            cmbColumn.HeaderText = "Ten dang nhap"
        End Sub
#End Region

        Public Sub HienThi(Dgv As DataGridView, bvn As BindingNavigator)
            Dim bs As New BindingSource()

            bs.DataSource = m_PhanQuyenData.LayPhanQuyen()
            bvn.BindingSource = bs
            Dgv.DataSource = bs
        End Sub

#Region "Them moi"
        Public Function ThemDongMoi() As DataRow
            Return m_PhanQuyenData.ThemDongMoi()
        End Function
        Public Sub ThemPhanQuyen(m_Row As DataRow)
            m_PhanQuyenData.ThemPhanQuyen(m_Row)
        End Sub
#End Region

#Region "Luu"
        Public Function LuuPhanQuyen() As Boolean
            Return m_PhanQuyenData.LuuPhanQuyen()
        End Function
#End Region

#Region "DangNhap"

        Private m_PhanQuyen As [String]
        Public Property PhanQuyen() As [String]
            Get
                Return m_PhanQuyen
            End Get
            Set(value As [String])
                m_PhanQuyen = value
            End Set
        End Property

        Public Function DangNhap(m_UserName As [String], m_Pass As [String]) As Integer
            m_PhanQuyenInfo.MatKhau = m_Pass
            m_PhanQuyenInfo.TenDangNhap = m_UserName

            Dim Pq As DataTable = m_PhanQuyenData.LayPhanQuyen(m_PhanQuyenInfo.TenDangNhap)

            If Pq.Rows.Count = 0 Then
                Return 0
            End If
            Dim m_Str As [String] = Pq.Rows(0)("MatKhau").ToString()

            If m_Str <> m_Pass Then
                Return 1
            Else

                PhanQuyen = Pq.Rows(0)("MaQuyen").ToString()
                Return 2
            End If
        End Function

        Public Function LayTenNguoiDung(m_Name As String) As [String]
            m_PhanQuyenInfo.TenDangNhap = m_Name

            Dim TenND As DataTable = m_PhanQuyenData.LayPhanQuyen(m_PhanQuyenInfo.TenDangNhap)

            If TenND.Rows.Count = 0 Then
                Return ""
            Else
                Return TenND.Rows(0)("TenDangNhap").ToString()
            End If
        End Function
#End Region

#Region "Doi mat khau"
        Public Sub DoiMatKhau(TenDN As [String], MatKhauMoi As [String])
            m_PhanQuyenData.DoiMatKhau(TenDN, MatKhauMoi)
        End Sub
#End Region
    End Class
End Namespace
